<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Member {
	
	// load config member system
	function memconfig(){
		// general
		$c['version']		= 1.0; // version of member system
		$c['emailconfirm'] 	= FALSE; // confirm email when register?
		$c['whatlogin']		= 'email';// email OR user
		$c['systemname']	= 'BeYourCyber Member System'; //change to your system name
		$c['emailsystem']	= 'b@entercm.com'; // main contact of this system
		$c['systemurl']		= 'http://beedev.com/'; // with tail slash ex http://google.com/
		$c['deleteself']	= TRUE;

		
		// table name
		$c['table_usersystem']	= "mem_usersystem";
		$c['table_userprofile']	= "mem_profile";
		$c['table_amphur']		= "amphur"; // can't change this line & when you change not any affect
		
		// allow field
		$c['field_businesstype']	= TRUE; // individual, business
		
		// profile
		$c['p_avatar']		= TRUE; //upload avatar
		$c['p_name']		= TRUE;
		$c['p_surname']		= TRUE;
		$c['p_gender']		= TRUE;
		$c['p_birthdate']	= TRUE;
		$c['p_married']		= TRUE;
		$c['p_address']		= TRUE;
		$c['p_city']		= TRUE;
		$c['p_state']		= TRUE;
		$c['p_zip']			= TRUE;
		$c['p_country']		= TRUE;
		$c['p_telephone']	= TRUE;
		$c['p_mobilephone']	= TRUE;
		$c['p_fax']			= TRUE;
		$c['p_job']			= TRUE;
		$c['p_msn']			= TRUE;
		$c['p_hi5']			= TRUE;
		$c['p_facebook']	= TRUE;
		$c['p_twitter']		= TRUE;
		$c['p_url']			= TRUE;
		$c['p_income']		= TRUE;
		$c['p_internet']	= TRUE;
		$c['p_family']		= TRUE;
		$c['p_personalid']	= TRUE;
		$c['p_emailnews']	= TRUE;
		$c['p_type']		= TRUE;
		
		// require field
		$c['re_p_avatar']		= FALSE;
		$c['re_p_name']			= TRUE;
		$c['re_p_surname']		= TRUE;
		$c['re_p_gender']		= TRUE;
		$c['re_p_birthdate']	= TRUE;
		$c['re_p_married']		= TRUE;
		$c['re_p_address']		= TRUE;
		$c['re_p_city']			= TRUE;
		$c['re_p_state']		= TRUE;
		$c['re_p_zip']			= TRUE;
		$c['re_p_country']		= TRUE;
		$c['re_p_telephone']	= TRUE;
		$c['re_p_mobilephone']	= TRUE;
		$c['re_p_fax']			= TRUE;
		$c['re_p_job']			= TRUE;
		$c['re_p_msn']			= TRUE;
		$c['re_p_hi5']			= TRUE;
		$c['re_p_facebook']		= TRUE;
		$c['re_p_twitter']		= TRUE;
		$c['re_p_url']			= TRUE;
		$c['re_p_income']		= TRUE;
		$c['re_p_internet']		= TRUE;
		$c['re_p_family']		= TRUE;
		$c['re_p_personalid']	= TRUE;
		$c['re_p_emailnews']	= TRUE;
		$c['re_p_type']			= TRUE;
		
		
		
		return $c;
	}
	
	function SetUserStatus($select)
	{
		$c[90]	= "Active Status"; // default user ** number in array range 1-127 only
		$c[20]	= "Suspend Status";
		$c[50]	= "Wait for activate"; //impact to mem_m
		if($select == '0'){
			return $c;
		}
		else{
			return $c[$select];
		}
	}
	
	
	function SetUserRank($select)
	{
		$c[60]	= "Normal User"; // default user ** number in array range 1-127 only
		$c[70]	= "Special User";
		$c[90]	= "Admin";
		if($select == '0'){
			return $c;
		}
		else{
			return $c[$select];
		}
	}
	
	function Setp_gender($select)
	{
		$c['M']	= "ชาย (male)";
		$c['F'] = "หญิง (female)";
		if($select == '0'){
			return $c;
		}
		else{
			return $c[$select];
		}
	}
	
	function Setp_married($select)
	{
		$c['S'] = "โสด (single)";
		$c['M']	= "สมรส (married)";
		$c['O']	= "หม้าย/หย่าร้าง (divorce)";
		
		if($select == '0'){
			return $c;
		}
		else{
			return $c[$select];
		}
	}
	
	function Setp_job($select)
	{
		$c[2] = "สถาปนิก/ดีใซเนอร์ (an architect / designer)";
		$c[3] = "ทนายความ/นักกฎหมาย (lawyer)";
		$c[4] = "เอนเตอร์เทน (entertainer)";
		$c[5] = "ที่ปรึกษา (consulting)";
		$c[6] = "ลูกค้าสัมพันธ์ (customer service)";
		$c[7] = "นักคอมพิวเตอร์ (computer)";
		$c[8] = "วิศวกร (engineering)";
		$c[9] = "พนักงานโรงแรม (waiter,waitress)";
		$c[10] = "ทรัพยากรบุคคล (human resource)";
		$c[11] = "ผู้บริหาร (executive)";
		$c[12] = "จัดซื้อ (purchase)";
		$c[13] = "นักเคมี/เภสัขกร (phamacist)";
		$c[14] = "ค้าขาย (seller)";
		$c[15] = "นักการตลาด (marketing)";
		$c[16] = "นักเรียน/นักศึกษา (student)";
		$c[17] = "รับราชการ/รัฐวิสาหกิจ (government/military)";
		$c[18] = "รับจ้างทั่วไป (employee)";
		$c[19] = "แม่บ้าน (housewife)";
		$c[20] = "เกษียณ (retire)";
		$c[21] = "ไม่ได้ประกอบอาชีพ (Unemployed)";
		$c[22] = "อื่น ๆ (others)";
		
		if($select == '0'){
			return $c;
		}
		else{
			return $c[$select];
		}
	}
	
	function Setp_income($select)
	{
		$c[2] = "น้อยกว่า (less than) 5,000 บาท (baht)";
		$c[3] = "5,000 - 10,000 บาท (baht)";
		$c[4] = "10,001 - 25,000 บาท (baht)";
		$c[5] = "25,001 - 50,000 บาท (baht)";
		$c[6] = "50,001 - 100,000 บาท (baht)";
		$c[7] = "มากกว่า (more than) 100,000 บาท (baht)";
		
		if($select == '0'){
			return $c;
		}
		else{
			return $c[$select];
		}
	}
	
	function Setp_internet($select)
	{
		$c[2] = "home";
		$c[3] = "office";
		$c[4] = "internet cafe";
		$c[5] = "others";
		
		if($select == '0'){
			return $c;
		}
		else{
			return $c[$select];
		}
	}
	
	function Setp_type($select)
	{
		$c[1] = "บุคคลธรรมดา (Individual) ";
		$c[2] = "บริษัทร้านค้า (Business)";
		
		if($select == '0'){
			return $c;
		}
		else{
			return $c[$select];
		}
	}
	
	function Setp_amphur($city,$id)
	{
		$CI =& get_instance();
   		$CI->load->model('mem_m');
   		$tmp = $CI->mem_m->getAmphur($city,$id);	
		return $tmp;
	}
	
	
	function Check_emailduplicate($email){
		$CI =& get_instance();
   		$CI->load->model('mem_m');
   		return $CI->mem_m->checkEmaildup($email);
		
	}
	
	function Check_userduplicate($user){
		$CI =& get_instance();
   		$CI->load->model('mem_m');
   		return $CI->mem_m->checkUsernamedup($user);
	}
	
	function Set_rulesignup(){
		$CI =& get_instance();
   		$CI->load->library('Member');
		$cf		= $CI->member->memconfig();
		$config = array();
		
		$config[] =	array(
                     'field'   => 'username', 
                     'label'   => 'Username', 
                     'rules'   => 'required|alpha_dash|min_length[2]|max_length[24]'
                  );
		$config[] =	array(
                     'field'   => 'password', 
                     'label'   => 'Password', 
                     'rules'   => 'required|min_length[5]|max_length[25]'
                  );
		$config[] =	array(
                     'field'   => 'confirmpassword', 
                     'label'   => 'Confirm Password', 
                     'rules'   => 'required|min_length[5]|max_length[25]|matches[password]'
                  );
		$config[] =	array(
                     'field'   => 'email', 
                     'label'   => 'Email', 
                     'rules'   => 'required|min_length[9]|max_length[70]|valid_email'
                  );
		
		if($cf['re_p_name']&& $cf['p_name']){
			$config[] =	array(
                     'field'   => 'p_name', 
                     'label'   => 'Name', 
                     'rules'   => 'required|alpha|min_length[2]|max_length[40]'
                  );
		}
		elseif(!$cf['re_p_name']&& $cf['p_name'])
		{
			$config[] =	array(
                     'field'   => 'p_name', 
                     'label'   => 'Name', 
                     'rules'   => 'alpha|min_length[2]|max_length[40]'
                  );
		}
		
		if($cf['re_p_surname']&& $cf['p_surname']){
			$config[] =	array(
                     'field'   => 'p_surname', 
                     'label'   => 'Surname', 
                     'rules'   => 'required|alpha|min_length[2]|max_length[40]'
                  );
		}
		elseif(!$cf['re_p_surname']&& $cf['p_surname'])
		{
			$config[] =	array(
                     'field'   => 'p_surname', 
                     'label'   => 'Surname', 
                     'rules'   => 'alpha|min_length[2]|max_length[40]'
                  );
		}
		
		if($cf['re_p_gender']&& $cf['p_gender']){
			$config[] =	array(
                     'field'   => 'p_gender', 
                     'label'   => 'Gender', 
                     'rules'   => 'required|alpha|exact_length[1]'
                  );
		}
		elseif(!$cf['re_p_gender']&& $cf['p_gender'])
		{
			$config[] =	array(
                     'field'   => 'p_gender', 
                     'label'   => 'Gender', 
                     'rules'   => 'alpha|exact_length[1]'
                  );
		}
		
		if($cf['re_p_birthdate']&& $cf['p_birthdate']){
			$config[] =	array(
                     'field'   => 'p_birthdate', 
                     'label'   => 'Birthdate', 
                     'rules'   => 'required|exact_length[10]|callback_Check_dateInput'
                  );
		}
		elseif(!$cf['re_p_birthdate']&& $cf['p_birthdate'])
		{
			$config[] =	array(
                     'field'   => 'p_birthdate', 
                     'label'   => 'Birthdate', 
                     'rules'   => 'exact_length[10]|callback_Check_dateInput'
                  );
		}
		
		if($cf['re_p_married']&& $cf['p_married']){
			$config[] =	array(
                     'field'   => 'p_married', 
                     'label'   => 'Married', 
                     'rules'   => 'required|alpha|exact_length[1]'
                  );
		}
		elseif(!$cf['re_p_married']&& $cf['p_married'])
		{
			$config[] =	array(
                     'field'   => 'p_married', 
                     'label'   => 'Married', 
                     'rules'   => 'alpha|exact_length[1]'
                  );
		}
		
		if($cf['re_p_address']&& $cf['p_address']){
			$config[] =	array(
                     'field'   => 'p_address', 
                     'label'   => 'Address', 
                     'rules'   => 'required|min_length[3]'
                  );
		}
		elseif(!$cf['re_p_address']&& $cf['p_address'])
		{
			$config[] =	array(
                     'field'   => 'p_address', 
                     'label'   => 'Address', 
                     'rules'   => 'min_length[3]'
                  );
		}
		
		if($cf['re_p_city']&& $cf['p_city']){
			$config[] =	array(
                     'field'   => 'p_city', 
                     'label'   => 'City', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_city']&& $cf['p_city'])
		{
			$config[] =	array(
                     'field'   => 'p_city', 
                     'label'   => 'Address', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_state']&& $cf['p_state']){
			$config[] =	array(
                     'field'   => 'p_state', 
                     'label'   => 'State', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_state']&& $cf['p_state'])
		{
			$config[] =	array(
                     'field'   => 'p_state', 
                     'label'   => 'State', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_zip']&& $cf['p_zip']){
			$config[] =	array(
                     'field'   => 'p_zip', 
                     'label'   => 'Zip', 
                     'rules'   => 'required|integer|exact_length[5]'
                  );
		}
		elseif(!$cf['re_p_zip']&& $cf['p_zip'])
		{
			$config[] =	array(
                     'field'   => 'p_zip', 
                     'label'   => 'Zip', 
                     'rules'   => 'integer|exact_length[5]'
                  );
		}
		
		if($cf['re_p_country']&& $cf['p_country']){
			$config[] =	array(
                     'field'   => 'p_country', 
                     'label'   => 'Country', 
                     'rules'   => 'required|alpha|exact_length[2]'
                  );
		}
		elseif(!$cf['re_p_country']&& $cf['p_country'])
		{
			$config[] =	array(
                     'field'   => 'p_country', 
                     'label'   => 'Country', 
                     'rules'   => 'alpha|exact_length[2]'
                  );
		}
		
		if($cf['re_p_telephone']&& $cf['p_telephone']){
			$config[] =	array(
                     'field'   => 'p_telephone', 
                     'label'   => 'Telephone', 
                     'rules'   => 'required|alpha_dash|min_length[6]|max_length[20]'
                  );
		}
		elseif(!$cf['re_p_telephone']&& $cf['p_telephone'])
		{
			$config[] =	array(
                     'field'   => 'p_telephone', 
                     'label'   => 'Telephone', 
                     'rules'   => 'alpha_dash|min_length[6]|max_length[20]'
                  );
		}
		
		if($cf['re_p_mobilephone']&& $cf['p_mobilephone']){
			$config[] =	array(
                     'field'   => 'p_mobilephone', 
                     'label'   => 'Mobile phone', 
                     'rules'   => 'required|callback_checkMobile'
                  );
		}
		elseif(!$cf['re_p_mobilephone']&& $cf['p_mobilephone'])
		{
			$config[] =	array(
                     'field'   => 'p_mobilephone', 
                     'label'   => 'Mobile phone', 
                     'rules'   => 'callback_checkMobile'
                  );
		}
		
		if($cf['re_p_fax']&& $cf['p_fax']){
			$config[] =	array(
                     'field'   => 'p_fax', 
                     'label'   => 'Fax number', 
                     'rules'   => 'required|alpha_dash|min_length[6]|max_length[20]'
                  );
		}
		elseif(!$cf['re_p_fax']&& $cf['p_fax'])
		{
			$config[] =	array(
                     'field'   => 'p_fax', 
                     'label'   => 'Fax number', 
                     'rules'   => 'alpha_dash|min_length[6]|max_length[20]'
                  );
		}
		
		if($cf['re_p_job']&& $cf['p_job']){
			$config[] =	array(
                     'field'   => 'p_job', 
                     'label'   => 'Job', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_job']&& $cf['p_job'])
		{
			$config[] =	array(
                     'field'   => 'p_job', 
                     'label'   => 'Job', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_msn']&& $cf['p_msn']){
			$config[] =	array(
                     'field'   => 'p_msn', 
                     'label'   => 'MSN Email', 
                     'rules'   => 'required|valid_email|max_length[70]'
                  );
		}
		elseif(!$cf['re_p_msn']&& $cf['p_msn'])
		{
			$config[] =	array(
                     'field'   => 'p_msn', 
                     'label'   => 'MSN Email', 
                     'rules'   => 'valid_email|max_length[70]'
                  );
		}
		
		if($cf['re_p_hi5']&& $cf['p_hi5']){
			$config[] =	array(
                     'field'   => 'p_hi5', 
                     'label'   => 'Hi5 URL', 
                     'rules'   => 'required|min_length[15]|max_length[150]|callback_check_url'
                  );
		}
		elseif(!$cf['re_p_hi5']&& $cf['p_hi5'])
		{
			$config[] =	array(
                     'field'   => 'p_hi5', 
                     'label'   => 'Hi5 URL', 
                     'rules'   => 'min_length[15]|max_length[150]|callback_check_url'
                  );
		}
		
		if($cf['re_p_facebook']&& $cf['p_facebook']){
			$config[] =	array(
                     'field'   => 'p_facebook', 
                     'label'   => 'Facebook', 
                     'rules'   => 'required|min_length[15]|max_length[170]|callback_check_url'
                  );
		}
		elseif(!$cf['re_p_facebook']&& $cf['p_facebook'])
		{
			$config[] =	array(
                     'field'   => 'p_facebook', 
                     'label'   => 'Facebook', 
                     'rules'   => 'min_length[15]|max_length[170]|callback_check_url'
                  );
		}
		
		if($cf['re_p_twitter']&& $cf['p_twitter']){
			$config[] =	array(
                     'field'   => 'p_twitter', 
                     'label'   => 'Twitter', 
                     'rules'   => 'required|min_length[20]|max_length[100]|callback_check_url'
                  );
		}
		elseif(!$cf['re_p_twitter']&& $cf['p_twitter'])
		{
			$config[] =	array(
                     'field'   => 'p_twitter', 
                     'label'   => 'Twitter', 
                     'rules'   => 'min_length[20]|max_length[100]|callback_check_url'
                  );
		}
		
		if($cf['re_p_url']&& $cf['p_url']){
			$config[] =	array(
                     'field'   => 'p_twitter', 
                     'label'   => 'Twitter', 
                     'rules'   => 'required|min_length[20]|max_length[100]|callback_check_url'
                  );
		}
		elseif(!$cf['re_p_url']&& $cf['p_url'])
		{
			$config[] =	array(
                     'field'   => 'p_twitter', 
                     'label'   => 'Twitter', 
                     'rules'   => 'min_length[20]|max_length[100]|callback_check_url'
                  );
		}
		
		if($cf['re_p_income']&& $cf['p_income']){
			$config[] =	array(
                     'field'   => 'p_income', 
                     'label'   => 'Income', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_income']&& $cf['p_income'])
		{
			$config[] =	array(
                     'field'   => 'p_income', 
                     'label'   => 'Income', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_internet']&& $cf['p_internet']){
			$config[] =	array(
                     'field'   => 'p_internet', 
                     'label'   => 'Internet', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_internet']&& $cf['p_internet'])
		{
			$config[] =	array(
                     'field'   => 'p_internet', 
                     'label'   => 'Internet', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_family']&& $cf['p_family']){
			$config[] =	array(
                     'field'   => 'p_family', 
                     'label'   => 'Family', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_family']&& $cf['p_family'])
		{
			$config[] =	array(
                     'field'   => 'p_family', 
                     'label'   => 'Family', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_personalid']&& $cf['p_personalid']){
			$config[] =	array(
                     'field'   => 'p_personalid', 
                     'label'   => 'Personal id', 
                     'rules'   => 'required|callback_check_personnalid'
                  );
		}
		elseif(!$cf['re_p_personalid']&& $cf['p_personalid'])
		{
			$config[] =	array(
                     'field'   => 'p_personalid', 
                     'label'   => 'Personal id', 
                     'rules'   => 'callback_check_personnalid'
                  );
		}
		
		if($cf['re_p_emailnews']&& $cf['p_emailnews']){
			$config[] =	array(
                     'field'   => 'p_emailnews', 
                     'label'   => 'Email receive', 
                     'rules'   => 'required|alpha|exact_length[1]'
                  );
		}
		elseif(!$cf['re_p_emailnews']&& $cf['p_emailnews'])
		{
			$config[] =	array(
                     'field'   => 'p_emailnews', 
                     'label'   => 'Email receive', 
                     'rules'   => 'alpha|exact_length[1]'
                  );
		}
		
		if($cf['re_p_type'] && $cf['p_type']){
			$config[] =	array(
                     'field'   => 'p_type', 
                     'label'   => 'Type', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_type'] && $cf['p_type'])
		{
			$config[] =	array(
                     'field'   => 'p_type', 
                     'label'   => 'Type', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		return $config;
	}
	
	function Set_ruleeditprofile(){
		$CI =& get_instance();
   		$CI->load->library('Member');
		$cf		= $CI->member->memconfig();
		$config = array();
		
		if($cf['re_p_name']&& $cf['p_name']){
			$config[] =	array(
                     'field'   => 'p_name', 
                     'label'   => 'Name', 
                     'rules'   => 'required|alpha|min_length[2]|max_length[40]'
                  );
		}
		elseif(!$cf['re_p_name']&& $cf['p_name'])
		{
			$config[] =	array(
                     'field'   => 'p_name', 
                     'label'   => 'Name', 
                     'rules'   => 'alpha|min_length[2]|max_length[40]'
                  );
		}
		
		if($cf['re_p_surname']&& $cf['p_surname']){
			$config[] =	array(
                     'field'   => 'p_surname', 
                     'label'   => 'Surname', 
                     'rules'   => 'required|alpha|min_length[2]|max_length[40]'
                  );
		}
		elseif(!$cf['re_p_surname']&& $cf['p_surname'])
		{
			$config[] =	array(
                     'field'   => 'p_surname', 
                     'label'   => 'Surname', 
                     'rules'   => 'alpha|min_length[2]|max_length[40]'
                  );
		}
		
		if($cf['re_p_gender']&& $cf['p_gender']){
			$config[] =	array(
                     'field'   => 'p_gender', 
                     'label'   => 'Gender', 
                     'rules'   => 'required|alpha|exact_length[1]'
                  );
		}
		elseif(!$cf['re_p_gender']&& $cf['p_gender'])
		{
			$config[] =	array(
                     'field'   => 'p_gender', 
                     'label'   => 'Gender', 
                     'rules'   => 'alpha|exact_length[1]'
                  );
		}
		
		if($cf['re_p_birthdate']&& $cf['p_birthdate']){
			$config[] =	array(
                     'field'   => 'p_birthdate', 
                     'label'   => 'Birthdate', 
                     'rules'   => 'required|exact_length[10]|callback_Check_dateInput'
                  );
		}
		elseif(!$cf['re_p_birthdate']&& $cf['p_birthdate'])
		{
			$config[] =	array(
                     'field'   => 'p_birthdate', 
                     'label'   => 'Birthdate', 
                     'rules'   => 'exact_length[10]|callback_Check_dateInput'
                  );
		}
		
		if($cf['re_p_married']&& $cf['p_married']){
			$config[] =	array(
                     'field'   => 'p_married', 
                     'label'   => 'Married', 
                     'rules'   => 'required|alpha|exact_length[1]'
                  );
		}
		elseif(!$cf['re_p_married']&& $cf['p_married'])
		{
			$config[] =	array(
                     'field'   => 'p_married', 
                     'label'   => 'Married', 
                     'rules'   => 'alpha|exact_length[1]'
                  );
		}
		
		if($cf['re_p_address']&& $cf['p_address']){
			$config[] =	array(
                     'field'   => 'p_address', 
                     'label'   => 'Address', 
                     'rules'   => 'required|min_length[3]'
                  );
		}
		elseif(!$cf['re_p_address']&& $cf['p_address'])
		{
			$config[] =	array(
                     'field'   => 'p_address', 
                     'label'   => 'Address', 
                     'rules'   => 'min_length[3]'
                  );
		}
		
		if($cf['re_p_city']&& $cf['p_city']){
			$config[] =	array(
                     'field'   => 'p_city', 
                     'label'   => 'City', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_city']&& $cf['p_city'])
		{
			$config[] =	array(
                     'field'   => 'p_city', 
                     'label'   => 'Address', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_state']&& $cf['p_state']){
			$config[] =	array(
                     'field'   => 'p_state', 
                     'label'   => 'State', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_state']&& $cf['p_state'])
		{
			$config[] =	array(
                     'field'   => 'p_state', 
                     'label'   => 'State', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_zip']&& $cf['p_zip']){
			$config[] =	array(
                     'field'   => 'p_zip', 
                     'label'   => 'Zip', 
                     'rules'   => 'required|integer|exact_length[5]'
                  );
		}
		elseif(!$cf['re_p_zip']&& $cf['p_zip'])
		{
			$config[] =	array(
                     'field'   => 'p_zip', 
                     'label'   => 'Zip', 
                     'rules'   => 'integer|exact_length[5]'
                  );
		}
		
		if($cf['re_p_country']&& $cf['p_country']){
			$config[] =	array(
                     'field'   => 'p_country', 
                     'label'   => 'Country', 
                     'rules'   => 'required|alpha|exact_length[2]'
                  );
		}
		elseif(!$cf['re_p_country']&& $cf['p_country'])
		{
			$config[] =	array(
                     'field'   => 'p_country', 
                     'label'   => 'Country', 
                     'rules'   => 'alpha|exact_length[2]'
                  );
		}
		
		if($cf['re_p_telephone']&& $cf['p_telephone']){
			$config[] =	array(
                     'field'   => 'p_telephone', 
                     'label'   => 'Telephone', 
                     'rules'   => 'required|alpha_dash|min_length[6]|max_length[20]'
                  );
		}
		elseif(!$cf['re_p_telephone']&& $cf['p_telephone'])
		{
			$config[] =	array(
                     'field'   => 'p_telephone', 
                     'label'   => 'Telephone', 
                     'rules'   => 'alpha_dash|min_length[6]|max_length[20]'
                  );
		}
		
		if($cf['re_p_mobilephone']&& $cf['p_mobilephone']){
			$config[] =	array(
                     'field'   => 'p_mobilephone', 
                     'label'   => 'Mobile phone', 
                     'rules'   => 'required|callback_checkMobile'
                  );
		}
		elseif(!$cf['re_p_mobilephone']&& $cf['p_mobilephone'])
		{
			$config[] =	array(
                     'field'   => 'p_mobilephone', 
                     'label'   => 'Mobile phone', 
                     'rules'   => 'callback_checkMobile'
                  );
		}
		
		if($cf['re_p_fax']&& $cf['p_fax']){
			$config[] =	array(
                     'field'   => 'p_fax', 
                     'label'   => 'Fax number', 
                     'rules'   => 'required|alpha_dash|min_length[6]|max_length[20]'
                  );
		}
		elseif(!$cf['re_p_fax']&& $cf['p_fax'])
		{
			$config[] =	array(
                     'field'   => 'p_fax', 
                     'label'   => 'Fax number', 
                     'rules'   => 'alpha_dash|min_length[6]|max_length[20]'
                  );
		}
		
		if($cf['re_p_job']&& $cf['p_job']){
			$config[] =	array(
                     'field'   => 'p_job', 
                     'label'   => 'Job', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_job']&& $cf['p_job'])
		{
			$config[] =	array(
                     'field'   => 'p_job', 
                     'label'   => 'Job', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_msn']&& $cf['p_msn']){
			$config[] =	array(
                     'field'   => 'p_msn', 
                     'label'   => 'MSN Email', 
                     'rules'   => 'required|valid_email|max_length[70]'
                  );
		}
		elseif(!$cf['re_p_msn']&& $cf['p_msn'])
		{
			$config[] =	array(
                     'field'   => 'p_msn', 
                     'label'   => 'MSN Email', 
                     'rules'   => 'valid_email|max_length[70]'
                  );
		}
		
		if($cf['re_p_hi5']&& $cf['p_hi5']){
			$config[] =	array(
                     'field'   => 'p_hi5', 
                     'label'   => 'Hi5 URL', 
                     'rules'   => 'required|min_length[15]|max_length[150]|callback_check_url'
                  );
		}
		elseif(!$cf['re_p_hi5']&& $cf['p_hi5'])
		{
			$config[] =	array(
                     'field'   => 'p_hi5', 
                     'label'   => 'Hi5 URL', 
                     'rules'   => 'min_length[15]|max_length[150]|callback_check_url'
                  );
		}
		
		if($cf['re_p_facebook']&& $cf['p_facebook']){
			$config[] =	array(
                     'field'   => 'p_facebook', 
                     'label'   => 'Facebook', 
                     'rules'   => 'required|min_length[15]|max_length[170]|callback_check_url'
                  );
		}
		elseif(!$cf['re_p_facebook']&& $cf['p_facebook'])
		{
			$config[] =	array(
                     'field'   => 'p_facebook', 
                     'label'   => 'Facebook', 
                     'rules'   => 'min_length[15]|max_length[170]|callback_check_url'
                  );
		}
		
		if($cf['re_p_twitter']&& $cf['p_twitter']){
			$config[] =	array(
                     'field'   => 'p_twitter', 
                     'label'   => 'Twitter', 
                     'rules'   => 'required|min_length[20]|max_length[100]|callback_check_url'
                  );
		}
		elseif(!$cf['re_p_twitter']&& $cf['p_twitter'])
		{
			$config[] =	array(
                     'field'   => 'p_twitter', 
                     'label'   => 'Twitter', 
                     'rules'   => 'min_length[20]|max_length[100]|callback_check_url'
                  );
		}
		
		if($cf['re_p_url']&& $cf['p_url']){
			$config[] =	array(
                     'field'   => 'p_twitter', 
                     'label'   => 'Twitter', 
                     'rules'   => 'required|min_length[20]|max_length[100]|callback_check_url'
                  );
		}
		elseif(!$cf['re_p_url']&& $cf['p_url'])
		{
			$config[] =	array(
                     'field'   => 'p_twitter', 
                     'label'   => 'Twitter', 
                     'rules'   => 'min_length[20]|max_length[100]|callback_check_url'
                  );
		}
		
		if($cf['re_p_income']&& $cf['p_income']){
			$config[] =	array(
                     'field'   => 'p_income', 
                     'label'   => 'Income', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_income']&& $cf['p_income'])
		{
			$config[] =	array(
                     'field'   => 'p_income', 
                     'label'   => 'Income', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_internet']&& $cf['p_internet']){
			$config[] =	array(
                     'field'   => 'p_internet', 
                     'label'   => 'Internet', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_internet']&& $cf['p_internet'])
		{
			$config[] =	array(
                     'field'   => 'p_internet', 
                     'label'   => 'Internet', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_family']&& $cf['p_family']){
			$config[] =	array(
                     'field'   => 'p_family', 
                     'label'   => 'Family', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_family']&& $cf['p_family'])
		{
			$config[] =	array(
                     'field'   => 'p_family', 
                     'label'   => 'Family', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		
		if($cf['re_p_personalid']&& $cf['p_personalid']){
			$config[] =	array(
                     'field'   => 'p_personalid', 
                     'label'   => 'Personal id', 
                     'rules'   => 'required|callback_check_personnalid'
                  );
		}
		elseif(!$cf['re_p_personalid']&& $cf['p_personalid'])
		{
			$config[] =	array(
                     'field'   => 'p_personalid', 
                     'label'   => 'Personal id', 
                     'rules'   => 'callback_check_personnalid'
                  );
		}
		
		if($cf['re_p_emailnews']&& $cf['p_emailnews']){
			$config[] =	array(
                     'field'   => 'p_emailnews', 
                     'label'   => 'Email receive', 
                     'rules'   => 'required|alpha|exact_length[1]'
                  );
		}
		elseif(!$cf['re_p_emailnews']&& $cf['p_emailnews'])
		{
			$config[] =	array(
                     'field'   => 'p_emailnews', 
                     'label'   => 'Email receive', 
                     'rules'   => 'alpha|exact_length[1]'
                  );
		}
		
		if($cf['re_p_type'] && $cf['p_type']){
			$config[] =	array(
                     'field'   => 'p_type', 
                     'label'   => 'Type', 
                     'rules'   => 'required|is_natural_no_zero'
                  );
		}
		elseif(!$cf['re_p_type'] && $cf['p_type'])
		{
			$config[] =	array(
                     'field'   => 'p_type', 
                     'label'   => 'Type', 
                     'rules'   => 'is_natural_no_zero'
                  );
		}
		return $config;
	}
	
	function Set_rulelogin(){
		$CI =& get_instance();
   		$CI->load->library('Member');
		$cf		= $CI->member->memconfig();
		$config = array();
		
		if($cf['whatlogin']== 'user'){
			$config[] =	array(
                     'field'   => 'username', 
                     'label'   => 'Username', 
                     'rules'   => 'required|alpha_dash|min_length[2]|max_length[24]'
                  );
		}
		else
		{
			$config[] =	array(
                     'field'   => 'email', 
                     'label'   => 'Email', 
                     'rules'   => 'required|min_length[9]|max_length[70]|valid_email'
                  );
		}
		
		
		$config[] =	array(
                     'field'   => 'password', 
                     'label'   => 'Password', 
                     'rules'   => 'required|min_length[5]|max_length[25]'
                  );
		
		return $config;
	}
	//show profile
	/// showProfile($profile,TRUE)
	function showProfile($profile,$mini){
		$CI =& get_instance();
		$CI->load->library('Member');
		$CI->load->library('Bee');
		$cf = $CI->member->memconfig();
		$s = "";
		if(!empty($profile['memprofile']['p_name']) && !empty($profile['memprofile']['p_surname']) && !empty($profile['memprofile']['p_country'])){
		
		$s = '<table name="showprofile" id="tableshowprofile">';
		$cnt = 1;
		if($cf['p_name']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">ชื่อ : </td><td>'.$profile['memprofile']['p_name'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">ชื่อ : </td><td>'.$profile['memprofile']['p_name'].'</td></tr>';
			}
			$cnt += 1;
		} 		
		if($cf['p_surname']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">นามสกุล : </td><td>'.$profile['memprofile']['p_surname'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">นามสกุล : </td><td>'.$profile['memprofile']['p_surname'].'</td></tr>';
			}
			$cnt += 1;
		}	
		if($cf['p_gender']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">เพศ : </td><td>'.$CI->member->Setp_gender($profile['memprofile']['p_gender']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">เพศ : </td><td>'.$CI->member->Setp_gender($profile['memprofile']['p_gender']).'</td></tr>';
			}
			$cnt += 1;
		} 	
		if($cf['p_birthdate'] && !$mini){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">วันเกิด : </td><td>'.$profile['memprofile']['p_birthdate'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">วันเกิด : </td><td>'.$profile['memprofile']['p_birthdate'].'</td></tr>';
			}
			$cnt += 1;
		} 	
		if($cf['p_married'] && !$mini){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">สถานภาพ : </td><td>'.$CI->member->Setp_married($profile['memprofile']['p_married']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">สถานภาพ : </td><td>'.$CI->member->Setp_married($profile['memprofile']['p_married']).'</td></tr>';
			}
			$cnt += 1;
		} 	
		if($cf['p_address']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">ที่อยู่ : </td><td>'.$profile['memprofile']['p_address'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">ที่อยู่ : </td><td>'.$profile['memprofile']['p_address'].'</td></tr>';
			}
			$cnt += 1;
		} 	
		if($cf['p_city']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">อำเภอ : </td><td>'.$CI->member->Setp_amphur(0,$profile['memprofile']['p_city']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">อำเภอ : </td><td>'.$CI->member->Setp_amphur(0,$profile['memprofile']['p_city']).'</td></tr>';
			}
			$cnt += 1;
		} 		
		if($cf['p_state']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">จังหวัด : </td><td>'.$CI->bee->Set_state($profile['memprofile']['p_state']).'</td></tr>';	
			}
			else
			{
				$s .= '<tr><td width="160px">จังหวัด : </td><td>'.$CI->bee->Set_state($profile['memprofile']['p_state']).'</td></tr>';
			}
			$cnt += 1;
		} 		
		if($cf['p_zip']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">รหัสไปรษณีย์ : </td><td>'.$profile['memprofile']['p_zip'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">รหัสไปรษณีย์ : </td><td>'.$profile['memprofile']['p_zip'].'</td></tr>';
			}
			$cnt += 1;
		} 				
		if($cf['p_country']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">ประเทศ : </td><td>'.$CI->bee->Set_country($profile['memprofile']['p_country']).'</td></tr>';		
			}
			else
			{
				$s .= '<tr><td width="160px">ประเทศ : </td><td>'.$CI->bee->Set_country($profile['memprofile']['p_country']).'</td></tr>';		
			}
			$cnt += 1;
		} 	
		if($cf['p_telephone']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">เบอร์โทรศัพท์ : </td><td>'.$profile['memprofile']['p_telephone'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">เบอร์โทรศัพท์ : </td><td>'.$profile['memprofile']['p_telephone'].'</td></tr>';
			}
			$cnt += 1;
		} 	
		if($cf['p_mobilephone']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">โทรศัพท์มือถือ : </td><td>'.$profile['memprofile']['p_mobilephone'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">โทรศัพท์มือถือ : </td><td>'.$profile['memprofile']['p_mobilephone'].'</td></tr>';
			}
			$cnt += 1;
		}
		if($cf['p_fax']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">แฟ็กซ์ : </td><td>'.$profile['memprofile']['p_fax'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">แฟ็กซ์ : </td><td>'.$profile['memprofile']['p_fax'].'</td></tr>';
			}
			$cnt += 1;
		} 		
		if($cf['p_job'] && !$mini){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">อาชีพ : </td><td>'.$CI->member->Setp_job($profile['memprofile']['p_job']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">อาชีพ : </td><td>'.$CI->member->Setp_job($profile['memprofile']['p_job']).'</td></tr>';
			}
			$cnt += 1;
		} 		
		if($cf['p_msn'] && !$mini){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">MSN : </td><td>'.$profile['memprofile']['p_msn'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">MSN : </td><td>'.$profile['memprofile']['p_msn'].'</td></tr>';
			}
			$cnt += 1;
		} 		
		if($cf['p_hi5'] && !$mini){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">HI5 : </td><td>'.auto_link($profile['memprofile']['p_hi5']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">HI5 : </td><td>'.auto_link($profile['memprofile']['p_hi5']).'</td></tr>';
			}
			$cnt += 1;
		} 		
		if($cf['p_facebook'] && !$mini){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">Facebook : </td><td>'.auto_link($profile['memprofile']['p_facebook']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">Facebook : </td><td>'.auto_link($profile['memprofile']['p_facebook']).'</td></tr>';
			}
			$cnt += 1;
		} 	
		if($cf['p_twitter'] && !$mini){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">Twitter : </td><td>'.auto_link($profile['memprofile']['p_twitter']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">Twitter : </td><td>'.auto_link($profile['memprofile']['p_twitter']).'</td></tr>';
			}
			$cnt += 1;
		} 	
		if($cf['p_url'] && !$mini){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">Website : </td><td>'.auto_link($profile['memprofile']['p_url']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">Website : </td><td>'.auto_link($profile['memprofile']['p_url']).'</td></tr>';
			}
			$cnt += 1;
		} 		
		if($cf['p_income'] && !$mini){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">รายได้ : </td><td>'.$CI->member->Setp_income($profile['memprofile']['p_income']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">รายได้ : </td><td>'.$CI->member->Setp_income($profile['memprofile']['p_income']).'</td></tr>';
			}
			$cnt += 1;
		} 	
		if($cf['p_internet'] && !$mini  && $profile['memprofile']['p_internet'] != '0'){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">สถานที่ใช้ Internet : </td><td>'.$CI->member->Setp_internet($profile['memprofile']['p_internet']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">สถานที่ใช้ Internet : </td><td>'.$CI->member->Setp_internet($profile['memprofile']['p_internet']).'</td></tr>';
			}
			$cnt += 1;
		} 	
		if($cf['p_family'] && !$mini){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">สมาชิกในครอบครัว : </td><td>'.$profile['memprofile']['p_family'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">สมาชิกในครอบครัว : </td><td>'.$profile['memprofile']['p_family'].'</td></tr>';
			}
			$cnt += 1;
		} 	
		if($cf['p_personalid']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">รหัสบัตรประชาชน : </td><td>'.$profile['memprofile']['p_personalid'].'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">รหัสบัตรประชาชน : </td><td>'.$profile['memprofile']['p_personalid'].'</td></tr>';
			}
			$cnt += 1;
		}	
		if($cf['p_type']){
			if($cnt%2){
				$s .= '<tr class="odd"><td width="160px">สมาชิกประเภท : </td><td>'.$CI->member->Setp_type($profile['memprofile']['p_type']).'</td></tr>';
			}
			else
			{
				$s .= '<tr><td width="160px">สมาชิกประเภท : </td><td>'.$CI->member->Setp_type($profile['memprofile']['p_type']).'</td></tr>';
			}
			$cnt += 1;
		} 		
		
		$s .= "</table>";
		}
		else
		{
			$s = "ยังไม่ทำการแก้ไข profile";
		}
		
		return $s;
	}

}
?>